package com.zyf.pattern.prototype.simple;

import java.util.ArrayList;
import java.util.Properties;

/**
 * create by yifeng
 */
public class CloneTest {
    public static void main(String[] args) {
        // 浅复制
        Prototype p = new Prototype();
        p.name = "zyf";
        p.list = new ArrayList<>();
        p.list.add("1");
        try {
            Prototype obj = (Prototype) p.clone();
            System.out.println(obj.name);
            System.out.println(obj.list.size());
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }

        // 复制的list带有对象
        PrototypeObject po = new PrototypeObject();
        po.name = "1aaaa";
        po.list = new ArrayList<>();
        po.list.add(new CloneTarget());
        try {
            PrototypeObject obj1 = (PrototypeObject) po.clone();
            System.out.println(obj1.name);
            System.out.println(obj1.list);
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }


    }
}
